package week.Aug0803;

/**
 * 链接：https://leetcode.cn/contest/weekly-contest-461/problems/trionic-array-i/
 * 题目：Q1. 三段式数组 I©leetcode
 */
public class IsTrionic {
    public static void main(String[] args) {
        System.out.println(isTrionic(new int[]{1,2,3,4,5,6}));
    }
    public static boolean isTrionic(int[] nums) {
        int n = nums.length;
        if (n < 4) {
            return false;
        }

        for (int p = 1; p <= n - 3; p++) {
            for (int q = p + 1; q <= n - 2; q++) {
                if (isIncreasing(nums, 0, p) &&
                        isDecreasing(nums, p, q) &&
                        isIncreasing(nums, q, n - 1)) {
                    return true;
                }
            }
        }
        return false;
    }

    private static boolean isIncreasing(int[] nums, int start, int end) {
        for (int i = start; i < end; i++) {
            if (nums[i] >= nums[i + 1]) {
                return false;
            }
        }
        return true;
    }

    private static boolean isDecreasing(int[] nums, int start, int end) {
        for (int i = start; i < end; i++) {
            if (nums[i] <= nums[i + 1]) {
                return false;
            }
        }
        return true;
    }
}
